/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pos.system.database;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Shameera
 */
public class ReportDataTable extends AbstractTableModel{
    
    private ResultSet  results;
    List<String[]> orders = new ArrayList<String[]>();
//    String[] columnName = new String[]{"Date" ,"Invoice","User","NumofItems","Total" };
    String[] columnName = new String[]{DBConstant.INVOICE_DATE ,DBConstant.INVOICE_INVOICE,DBConstant.INVOICE_USER,DBConstant.INVOICE_ITEM_COUNT,DBConstant.INVOICE_TOTAL };

    public ReportDataTable() {
    }

    
    public ReportDataTable(ResultSet results) {
        this.results = results;
        try {
            init();
        } catch (SQLException ex) {
            Logger.getLogger(ReportDataTable.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    
    

    @Override
    public int getRowCount() {
        return orders.size();
    }

    @Override
    public int getColumnCount() {
        return columnName.length;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
       return orders.get(rowIndex)[columnIndex];
    }

    private void init() throws SQLException {
        while(results.next()){
           orders.add(new String[]{ results.getString(DBConstant.INVOICE_DATE), results.getString(DBConstant.INVOICE_INVOICE) , results.getString(DBConstant.INVOICE_USER),
                  results.getString(DBConstant.INVOICE_ITEM_COUNT), results.getString(DBConstant.INVOICE_TOTAL)});
        }
    }

    @Override
    public String getColumnName(int column) {
        return columnName[column];
    }
    
    
    
}

